package Controllers;

import Exceptions.DaoException;
import Interfaces.ISignUp_Dao;
import Models.SignUp;
import javax.swing.JOptionPane;

public class SignUp_Controller {

    private ISignUp_Dao x;

    public SignUp_Controller(ISignUp_Dao x) {
        this.x = x;
    }

    SignUp_Controller() {

    }

    public SignUp Validate2(String Name, String LastName, String Phone, String Email, String Username, String Password, String Repass)
            throws IllegalArgumentException, DaoException {

        if (Name.isEmpty() || LastName.isEmpty() || Phone.isEmpty() || Email.isEmpty() || Username.isEmpty() || Password.isEmpty() || Repass.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Empty Field");
        } else if (!Email.contains("@") || !Email.contains(".")) {
            JOptionPane.showMessageDialog(null, "Wrong Email");
        } else if (Phone.matches("[0-9]+") == false) {
            JOptionPane.showMessageDialog(null, "Wrong Phone");
        } else if (Phone.length() > 10 || Phone.length() < 10) {
            JOptionPane.showMessageDialog(null, "Wrong Phone");
        } else if (!Password.equals(Repass)) {
            JOptionPane.showMessageDialog(null, "Password and Repass do not match");
        } else {
            JOptionPane.showMessageDialog(null, "Success");
        }
        try {
            return x.ValidateSignUp(Name, LastName, Phone, Email, Username, Password, Repass);
        } catch (DaoException e) {
            throw e;
        }

    }

}
